/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chameleon.view.command;


import chameleon.view.input.Input;

/**
 *
 * @author simon
 */
public class CommandFactory {

    /**
     * This function creates the command corresponding to the user input and checks
     * if given arguments are correct.
     * @param input
     * @param cmd
     * @return
     */

    public static Command createCommand (Input input, String cmd){
        String[] command = cmd.split(" -");
        
        

        //TO DO CORRECTION OF call

        //read_model -gameName modelFile
        if (command[0].equals("read_model")){
            if (command.length==2)
                return new ReadModelCmd(input, command[1],command[1].equals("h"));
            else
                return new ReadModelCmd(input, null, true);
        }
        else if (command[0].equals("quit"))
            return new QuitCmd();
        else if (command[0].equals("build_model"))
            return new BuildModelCmd(input,command.length!=1);
        else if (command[0].equals("solve_game"))
            return new SolveGameCmd(input,command.length!=1);
        else if (command[0].equals("compute_pre_image")){
            if (command.length > 1){
                return new ComputePreImageCommand(input, command, command[1].equals("h"));
            }
            else
                return new ComputePreImageCommand(input, null, true);
        }
        else if (command[0].equals("compute_strategy")){
            if (command.length > 1){
                return new ComputeStrategyCommand(input, command, command[1].equals("h"));
            }
            else
                return new ComputeStrategyCommand(input, null, true);
        }
        else if (command[0].equals("compute_ltl_strategy")){
            if (command.length > 1){
                return new ComputeLtlStrategyCommand(input, command, command[1].equals("h"));
            }
            else
                return new ComputeLtlStrategyCommand(input, null, true);
        }
        else if (command[0].equals("print_strategy")){
            if (command.length == 2)
                return new PrintStrategyCommand(input,command[1],command[1].equals("h"));
            else
                return new PrintStrategyCommand(input,"",true);
        }
        else if (command[0].equals("modify_order_strategy")){
            if (command.length == 2)
                return new ModifyOrderStrategyCommand(input,command[1],command[1].equals("h"));
            else
                return new ModifyOrderStrategyCommand(input,"",true);
        }
        /**addTransition -Player(P1|P2) -format(-ltl|-aut|-smv) (String|file) mapTable link
         * the first file is the description of the transition and the second
         * is the correspondance table between inputFormat and svm model.
         * If the type is -smv the mapTable must be null
         */
        else if (command[0].equals("addTransition"))


            if (command.length == 4)
                return new AddTransitionCmd(input,command[1],
                    command[2],
                    command[3],
                    false);
            else
                return new AddTransitionCmd(input, null,null, null,  true);
        else if (command[0].equals("help"))
            return new HelpCommand(input);
        else if (command[0].equals("write_flat_model"))
            return new WriteFlatModelCommand(input,command.length!=1);
        else if (command[0].equals("check_reach_target")){
            String[] argv = cmd.split(" ");
                return new checkReachTargetCommand(input,argv);
        }
        else if (command[0].equals("extract_subset")){
            if (command.length == 2)
                return new ExtractSubsetCommand(input, false, command[1]);
            else
                return new ExtractSubsetCommand(input, true, "");
        }
        
        else if (command[0].equals("add_new_var")){
            return new AddNewVariableCommand(input, true, command[1]);
        }
        
        else if (command[0].equals("check_strategy_is_winning"))
            return new CheckStrategyIsWinning(input,command.length>1);

        else if (command[0].equals("restore_init_strategy"))
            return new RestoreInitStrategy(input,command.length>1);
        
        else if (command[0].equals("check_reach_deadlock")){
            String[] argv = cmd.split(" ");
                return new checkReachDeadlockCommand(input,argv);
        }

        else if (command[0].equals("check_avoid_target")){
            String[] argv = cmd.split(" ");
                return new checkAvoidTargetCommand(input,argv);
        }
        else if (command[0].equals("check_avoid_deadlock")){
            String[] argv = cmd.split(" ");
                return new checkAvoidDeadlockCommand(input,argv);
        }

        else if (command[0].equals("check_buchi_game")){
            String[] argv = cmd.split(" ");
                return new checkBuchiGameCommand(input,argv);
        }

        else if (command[0].equals("check_ltl_game")){
            String[] argv = cmd.split(" ");
                return new checkLtlGameCommand(input,argv);
        }

        else if (command[0].equals("check_GR_game")){
            String[] argv = cmd.split(" ");
                return new checkGRGameCommand(input,argv);
        }
        else if (command[0].equals("write_order")){
            String[] argv = cmd.split(" ");
                return new WriteOrderCommand(input,argv);
        }
        
        else if (command[0].equals("show_vars")){
            String[] argv = cmd.split(" ");
                return new ShowVarsCommand(input,argv);
        }
        else{
            return new ErrorCommand(input);
        }
    }


}
